package com.meizi.user.service.bo;

import com.meizi.core.tool.exception.ValidException;
import com.meizi.user.service.enums.LoginTypeEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import javax.validation.constraints.NotNull;

/**
 * @author meizi
 * @email enjoymeizi@gmail.com
 * @date 2020/11/26 14:23
 */
@Data
@Slf4j
public class AuthLoginBo {
    private String username;
    private String password;

    private String phone;
    private String code;

    private String openId;

    /**
     * @see LoginTypeEnum
     */
    @NotNull
    private Integer loginType;

    public void validData(BindingResult bindingResult) {
        log.info("bindingResult===>{}",this);
        if(bindingResult.hasErrors()){
            StringBuilder stringBuilder=new StringBuilder();
            for(ObjectError oe:bindingResult.getAllErrors()){
                stringBuilder.append(oe.getDefaultMessage()+"\n");
            }
            throw new ValidException(stringBuilder.toString());
        }
    }
}
